package fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.example.administrator.ci_edit.R;

import java.util.Random;

import activity.MainActivity;
import activity.PoemSelectActivity;
import activity.PoemShowActivity;

/**
 * Created by hello world on 2017/7/21.
 */

public class XieciFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view= inflater.inflate(R.layout.activity_main, container, false);

        Button btn1 = (Button)view.findViewById(R.id.select_poem_btn);
        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent=new Intent();
                intent.setClass(getActivity(), PoemSelectActivity.class);
                Log.d("SupperActivity","准备进行页面跳转了");
                startActivity(intent);
                Log.d("SupperActivity","页面跳转了");
            }
        });

        Button btn2 = (Button)view.findViewById(R.id.random_btn);
        btn2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //生成一个随机数
                Random random=new Random();
                int randomNum=random.nextInt(98);
                randomNum=randomNum+1;//不允许生成为0的随机数Intent intent=new Intent();

                //传给界面PoemShowActivity
                Intent intent=new Intent();
                intent.setClass(getActivity(), PoemShowActivity.class);
                intent.putExtra("extra_mengid",randomNum);
                startActivity(intent);
            }
        });
        return view;
    }
}

